import "./assets/css/reset.css";
import "./assets/scss/main.scss";
import "./assets/css/iconfont.css";

console.log(111, "资源加载完成...")
const root = document.getElementById('root');
if (root) {
    root.innerHTML = '<h2>Hello from TypeScript!</h2>';
}

// 测试ts
import { isNonEmpty,
  regexValidate,
  generateVerifyCode,
  deepClone,
  debounce,
  throttle,
  commonRegex
} from "./assets/ts/tool"

// 字符串非空校验
console.log(isNonEmpty(''))
console.log(isNonEmpty('hello'));


// 正则校验（预定义模式）
console.log(regexValidate('13812345678', 'mobile'));
console.log(regexValidate('13812345678', commonRegex.mobile));
// 正则校验（自定义模式）
console.log(regexValidate('13812345678', /^1[3-9]\d{9}$/));

// 生成验证码
console.log(generateVerifyCode()); // 4位随机码
console.log(generateVerifyCode(6)); // 6位随机码

// 深拷贝
const obj = { a: 1, b: [2, 3], c: { d: 4 } };
const cloned = deepClone(obj);
console.log(cloned.b === obj.b); // false（深拷贝成功）

// 防抖使用
const search = (keyword: string) => console.log('搜索：', keyword);
const debouncedSearch = debounce(search, 500);
// input事件触发时调用debouncedSearch

// 节流使用
const scrollHandler = () => console.log('滚动事件');
const throttledScroll = throttle(scrollHandler, 300);
// scroll事件触发时调用throttledScroll